<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
         <!-- <a-col :xl="4" :lg="7" :md="6" :sm="24">
            <a-form-item label="创建人">
              <a-input placeholder="请输入创建人" v-model="queryParam.createBy"></a-input>
            </a-form-item>
          </a-col>-->
<!--
          <a-col :xl="4" :lg="7" :md="6" :sm="24">
            <a-form-item label="文件分组">
              <j-dict-select-tag placeholder="请选择文件分组" v-model="queryParam.dataGroup" dictCode="file_group"/>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="5" :md="6" :sm="24">
            <a-form-item label="上传类型">
              <j-dict-select-tag placeholder="请选择上传类型" v-model="queryParam.uploadType" dictCode="upload_type"/>
            </a-form-item>
          </a-col>-->
          <a-col :xl="4" :lg="5" :md="6" :sm="24">
            <a-form-item label="是否应用">
              <j-dict-select-tag placeholder="请选择是否应用" v-model="queryParam.isApply" dictCode="yn"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="6" :md="12" :sm="24">
            <a-form-item label="上传时间">
              <j-date placeholder="开始日期" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="结束日期" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>

            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
     <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('文件上传日志')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      &lt;!&ndash; 高级查询区域 &ndash;&gt;
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="textSlot" slot-scope="text">
          <j-text-slot v-model="text" ></j-text-slot>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <j-file-slot v-model="text"></j-file-slot>
        </template>

        <span slot="action" slot-scope="text, record">
         <!-- <a @click="handleEdit(record)">编辑</a>-->
          <a-popconfirm title="确定删除吗?" v-has="'sys:file:data:delete'" @confirm="() => handleDelete(record)">
            <a>删除</a>
          </a-popconfirm>
         <!-- <a-divider type="vertical" />-->
          <!--<a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" v-has="'sys:file:data:delete'" @confirm="() => handleDelete(record)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>
    <file-data-modal ref="modalForm" @ok="modalFormOk"></file-data-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import FileDataModal from './modules/FileDataModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { deleteAction } from '@/api/manage'
  import { colAuthFilter } from "@/utils/authFilter"

  export default {
    name: 'FileDataList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      FileDataModal,
    },
    data () {
      return {
        description: '文件上传日志管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'文件',
            align:"center",
            dataIndex: 'url',
            scopedSlots: {customRender: 'fileSlot'}
          },
          {
            title:'后缀',
            align:"center",
            dataIndex: 'suffix'
          },

        /*  {
            title:'文件分组',
            align:"center",
            dataIndex: 'dataGroup_dictText'
          },
          {
            title:'上传类型',
            align:"center",
            dataIndex: 'uploadType_dictText'
          },*/
          {
            title:'是否应用',
            align:"center",
            dataIndex: 'isApply_dictText'
          },
          {
            title:'上传时间',
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>16?text.substr(0,16):text)
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/sys/file/data/list",
          delete: "/sys/file/data/delete",
          deleteBatch: "/sys/file/data/deleteBatch",
          exportXlsUrl: "/sys/file/data/exportXls",
          importExcelUrl: "sys/file/data/importExcel",

        },
        queryParam: {
          delFlag:"0"
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
      this.disableMixinCreated=true;
      this.columns = colAuthFilter(this.columns,'fileLog:');
      this.loadData();
      this.initDictConfig();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      batchDel: function () {
        if(!this.url.deleteBatch){
          this.$message.error("请设置url.deleteBatch属性!")
          return
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录');
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            //选中的行数据
            if(this.selectionRows[a].isApply != '0'){
              this.$message.error("第 "+(a+1)+" 条选中文件已应用，不可删除！")
              return
            }
            ids += this.selectedRowKeys[a] + ",";
          }
          var that = this;
          this.$confirm({
            title: "确认删除",
            content: "是否删除选中数据?",
            onOk: function () {
              that.loading = true;
              deleteAction(that.url.deleteBatch, {ids: ids}).then((res) => {
                if (res.success) {
                  //重新计算分页问题
                  that.reCalculatePage(that.selectedRowKeys.length)
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
        }
      },
      handleDelete(row){
        if(!this.url.delete){
          this.$message.error("请设置url.delete属性!")
          return
        }
        //console.log(row);
        if(row.isApply != '0'){
          this.$message.error("已应用文件不可删除！")
          return
        }
        var that = this;
        deleteAction(this.url.delete, {id: row.id}).then((res) => {
          if (res.success) {
            //重新计算分页问题
            that.reCalculatePage(1)
            that.$message.success(res.message);
            that.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
        fieldList.push({type:'datetime',value:'createTime',text:'创建日期'})
        fieldList.push({type:'string',value:'url',text:'文件地址',dictCode:''})
        fieldList.push({type:'string',value:'suffix',text:'后缀',dictCode:''})
        fieldList.push({type:'string',value:'isApply',text:'是否应用',dictCode:'yn'})
        fieldList.push({type:'string',value:'fileGroup',text:'文件分组',dictCode:'file_group'})
        fieldList.push({type:'string',value:'uploadType',text:'上传类型',dictCode:'upload_type'})
        this.superFieldList = fieldList
      },
      imageOpen(){
        console.log(sss)
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>